<?php
include_once('common/header.php');	
if($AppUI->id <= 0 || !isset($_SERVER['HTTP_REFERER'])) {	
	$arrJson = array('error'=>1,'msg'=>$arrError[1]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intType 	= $objRequest->getParam('type', 0);
$objCover	= new Cover();
if($intType == 0) {
	$intCoverId	= $objRequest->getParam('coverid', 0);
	$intXpos	= $objRequest->getParam('xc', 0);
	$intYpos	= $objRequest->getParam('yc', 0);
	$intTpos	= $objRequest->getParam('top', 0);	
	$info		= $objCover->get($intCoverId);
	$uCover		= $objCover->getCoverByUserId($AppUI->id);
	$strPlace	= '_' . $AppUI->hex . '.';
	$strImage	= $info['image'];
	$strThumb	= str_replace('.', $strPlace, $strImage);
	if($info['coverid'] == $uCover['coverid']) {	
		if(file_exists(DIR_COVER_THUMB . $strThumb))
			@unlink(DIR_COVER_THUMB . $strThumb);
		$objCover->updatePathExtend($AppUI->id, $intCoverId, $intTpos, $strThumb);
	}
	Vfriend_Upload::uploadCoverThumb($strImage,$strThumb,$intXpos,$intYpos);
	$arrJson 	= array('error'=>0,'msg'=>$arrMessage[12]);
}elseif($intType == 1) {
	$intUserId	= $AppUI->id;
	$arrUser	= $objCover->getAll($intUserId);
	$arrUcover	= $objCover->getCoverByUserId($intUserId);
	$intCoverId	= $arrUcover['coverid'];
	$intWidth	= COVER_IMAGE_FULL_WIDTH;
	$intHeight	= COVER_IMAGE_FULL_HEIGHT;
	if($intCoverId > 0) {
		$srcFileName = DIR_COVER_FULL . $arrUcover['image'];
		list( $intWidth, $intHeight) = getimagesize( $srcFileName );
	}
	$intVon					= $objVfriendUser->getAccount($intUserId, 1);
	$this->view->arrUser  	= $arrUser;
	$this->view->ucover	  	= $arrUcover;
	$this->view->intHeight	= $intHeight;
	$this->view->intWidth	= $intWidth;
	$objView 		= Zend_Registry::get('objView');
	$strData		= $objView->fetch('account/box-cover.tpl');
	$arrJson 	= array('dhtml'=>$strData,'coverid'=>$intCoverId,'von'=>Vfriend_Function::numberFormat($intVon));
}

echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';

exit();
?>